﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Ecreate.Popedom.Dao.Hibernate
{
    public class MenuDaoImpl:IMenuDao
    {
        public IList<tMenu> getAll()
        {
            NHibernate.ISession s = Utility.getSession();
            return s.CreateQuery(" from tMenu t where 1=1 ").List<tMenu>();
        }

        public IList<tMenu> getParentMenuList()
        {
            NHibernate.ISession s = Utility.getSession();
            return s.CreateQuery(" from tMenu t where 1=1 and t.Menu.Id is null or  t.Menu.Id='' ").List<tMenu>();
        }

        public IList<tMenu> getMenusByParentID(string Id)
        {
            String hsql = (new StringBuilder(" from tMenu m where m.Menu.Id='")).Append(Id).Append("' order by m.Menuorder").ToString();
            NHibernate.ISession s = Utility.getSession();
            return s.CreateQuery(hsql).List<tMenu>();
        }

        public tMenu getById(string id)
        {
            NHibernate.ISession s = Utility.getSession();
            return s.Load<tMenu>(id);
        }

        public void Delete(tMenu Model)
        {
            Utility.DeleteModel(Model);

        }
        public void Update(tMenu Model)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            s.Update(Model); ;
            s.Transaction.Commit();
        }
        public void Insert(tMenu Model)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            s.Save(Model); ;
            s.Transaction.Commit();
        }
    }
}
